package com.haier.common;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.ser.CustomSerializerFactory;

public abstract class AbstractController {

	protected  String pojo2String(Object object,String contentType)
	{
		OutputStream out = new ByteArrayOutputStream();
		try {
			ObjectMapper mapper = new ObjectMapper();
			mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
			
			CustomSerializerFactory serializerFactory= new CustomSerializerFactory(); 
			serializerFactory.addSpecificMapping(String.class, new StringUnicodeSerializer());  
			mapper.setSerializerFactory(serializerFactory);  

			JsonGenerator jsonGenerator = mapper.getJsonFactory().createJsonGenerator(out);

			jsonGenerator.writeObject(object);
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				out.flush();
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return "("+out.toString()+")";
	}
}
